<?php

namespace app\common\model;

use app\admin\controller\hospital\GeneralTimes;
use think\Controller;
use think\Model;


class Hospital extends Model
{

    

    

    // 表名
    protected $name = 'hospital';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'images_arr',

    ];
    public function getAddressTextArrAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['province']) ? $data['province'] : '');
        $value1 = $value ? $value : (isset($data['city']) ? $data['city'] : '');
        $value2 = $value ? $value : (isset($data['area']) ? $data['area'] : '');
        $value3 = $value ? $value : (isset($data['address']) ? $data['address'] : '');
        return $value.$value1.$value2.$value3;
    }
    public function getImagesArrAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['hospital_images']) ? $data['hospital_images'] : '');
        $list=explode(',',$value);
        $images=[];
        foreach ($list as $k=>$v){
            $images[]=cdnurl($v,true);
        }
        return $images;
    }

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);

        });
    }

    
    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
